﻿using StudySystem.MainLogic;
using StudySystem.MainLogic.Items;
using StudySystem.SQLServer;
using StudySystem.Windows;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace StudySystem
{
    /**
     *程序的各种主要逻辑
     */
    static class Logic
    {
        #region  已被注释
        //private static string _userID;
        //private static int _subjectID;
        //private static int _questionID;

        //public static string UserID { get => _userID; set => _userID = value; }
        //public static int SubjectID { get => _subjectID; set => _subjectID = value; }
        //public static int QuestionID { get => _questionID; set => _questionID = value; }
        #endregion

        #region 不用的函数   删除的
        ///// <summary>
        ///// 检查用户信息
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="password"></param>
        ///// <returns></returns>
        //public static bool CheckEnter(string id, string password)
        //{
        //    UserInformation user = DbHelper.GetUserInformation(id, password);
        //    UserManagement.user = user;
        //    if (user != null)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        ///// <summary>
        ///// 添加一个科目
        ///// </summary>
        ///// <param name="subjectName"></param>
        //public static bool InsertASubject(string subjectName)
        //{
        //    if (CheckSubjectName(subjectName) == false)
        //        return false;

        //    //数据库添加完成
        //    DbHelper.SafeInsertASubject(subjectName);
        //    //删除原有的科目
        //    FormController.DeleteElement(FormController.subjectForm.GetFlow());
        //    //dt更新
        //    DbHelper.GetSubjects(UserManagement.user.UserID, ref UserManagement.ds);
        //    //界面更新
        //    GetSubject();
        //    return true;
        //}

        //public static void RightEnter()
        //{
        //    UserManagement.ds.Tables.Clear();
        //    GetDS();
        //    FormController.OpenSubjectForm();
        //}

        //public static void WrongEnter()
        //{

        //    MessageBox.Show("用户ID或密码错误，请重新输入");
        //}

        //private static void GetDS()
        //{
        //    //DbHelper.GetSubjects(UserManagement.user.UserID, ref UserManagement.ds);//获得所有学科
        //    DbHelper.GetQuestions(ref UserManagement.ds);//获得所有问题
        //}


        ///// <summary>
        ///// 将ds中的subjectTable在学科界面上显示出来
        ///// 内存中保存了当前用户id，故不需参数
        ///// </summary>
        //public static void GetSubject()
        //{
        //    List<Subject> subjects = new List<Subject>();
        //    //FormController.SubjectLinkDB(subjects, UserManagement.ds.Tables["subjectTable"],"SubjectID");
        //    FlowLayoutPanel f = FormController.subjectForm.GetFlow();
        //    FormController.LoadSubject(subjects,f);
        //}

        ///// <summary>
        ///// 检查是否有同名的课程名称,有则返回false，无则返回true
        ///// </summary>
        ///// <param name="subName"></param>
        ///// <returns></returns>
        //public static bool CheckSubjectName(string subName)
        //{
        //    DataTable dt = UserManagement.ds.Tables["subjectTable"];
        //    foreach (DataRow record in dt.Rows)
        //    {
        //        if (subName == record["subjectName"].ToString())
        //            return false;
        //    }
        //    return true;
        //}

        //public static bool ModifySubName(int subjectID, string newName)
        //{
        //    if (CheckSubjectName(newName) == false)
        //        return false;
        //    //数据库数据更新
        //    DbHelper.SafeModifySubName(subjectID, newName);
        //    //删除原有的科目
        //    FormController.DeleteElement(FormController.subjectForm.GetFlow());
        //    //更新dt
        //    //DbHelper.GetSubjects(UserManagement.user.UserID, ref UserManagement.ds);
        //    //界面更新
        //    //GetSubject();
        //    return true;
        //}


        //public static bool InsertAQuestion(string subjectID, string question, string answer,FlowLayoutPanel flp)
        //{
        //    if (!FormController.CheckQuestion(question, answer))
        //        return false;
        //    DbHelper.InsertAQuestion(subjectID, question, answer);
        //    //删除原有的科目
        //    FormController.DeleteElement(flp);
        //    //dt更新
        //    DbHelper.GetQuestions(ref UserManagement.ds);
        //    //界面更新
        //    //GetQuestion(subjectID,flp);
        //    return true;
        //}






        ///// <summary>
        ///// 获得当前学科的所有问题
        ///// 同时在问题界面上显示出来
        ///// </summary>
        ///// <param name="subjectId"></param>
        //public static void GetQuestion(string subjectId, FlowLayoutPanel flp)
        //{
        //    //DbHelper.GetQuestions(subjectId, ref UserManagement.ds);
        //    List<Question> questions = new List<Question>();
        //    FormController.QuestionLinkDB(subjectId, questions, UserManagement.ds.Tables["questionTable"], "QuestionID");
        //    //FlowLayoutPanel f = FormController.questionForm.GetFlow();
        //    FormController.LoadQuestion(questions, flp);
        //}





        //public static void DeleteASubject(int subjectID)
        //{
        //    //删除数据库中的数据
        //    //DbHelper.DeleteASubject(subjectID);
        //    //删除原有的科目
        //    FormController.DeleteElement(FormController.subjectForm.GetFlow());
        //    //更新dt
        //    //DbHelper.GetSubjects(UserManagement.user.UserID, ref UserManagement.ds);
        //    //界面更新
        //    //GetSubject();
        //}




        //public static void DeleteAQuestion(string questionID, FlowLayoutPanel flp,string subjectID)
        //{
        //    //删除数据库中的数据
        //    DbHelper.DeleteAQuestion(questionID);
        //    //删除原有的问题
        //    FormController.DeleteElement(flp);
        //    //更新dt
        //    DbHelper.GetQuestions(ref UserManagement.ds);
        //    //界面更新
        //    //GetQuestion(subjectID,flp);
        //}

        //public static void ModifyQuestion(string question,string answer,int questionID,FlowLayoutPanel flp,string subjectID)
        //{
        //    //修改数据库
        //    DbHelper.SafeModifyQuestion(question, answer, questionID);
        //    //删除原有的科目
        //    FormController.DeleteElement(flp);
        //    //更新dt
        //    DbHelper.GetQuestions(ref UserManagement.ds);
        //    //界面更新
        //    //GetQuestion(subjectID,flp);
        //}

        #endregion




    }
}
